{% import "macros/diff_text.html.j2" as DIFF_TEXT %}

{# TODO: документарий #}
{% macro TAG(change, project_manager) -%}
  <table class="table table-borderless" style="width:100%">
    <thead>
      <tr>
        <th scope="col" style="width: 1%"></th>
        <th scope="col"></th>
      </tr>
    </thead>
    <tbody>
      {% for key, change_section in change.dict_diff().items() %}
        <tr>
          {% if key == change.DiffKey.caption %}
            <td>Наименование:</td>
            <td>{{ DIFF_TEXT.TAG(change, change_section) }}</td>
          {% elif key == change.DiffKey.content %}
            <td>Описание:</td>
            <td>{{ DIFF_TEXT.TAG(change, change_section) }}</td>
          {% elif key == change.DiffKey.state %}
            <td>Состояние:</td>
            <td>
              {%- for key, change_sub_section in change_section.items() -%}
                {{ DIFF_TEXT.TAG(change, change_sub_section) }}
              {%- endfor -%}
            </td>
          {% elif key == change.DiffKey.project %}
            <td>Проект:</td>
            <td>
              {%- for key, change_sub_section in change_section.items() -%}
                {{ DIFF_TEXT.TAG(change, change_sub_section) }}
              {%- endfor -%}
            </td>
          {% elif key == change.DiffKey.parent %}
            <td>Предок:</td>
            <td>
              {%- for key, change_sub_section in change_section.items() -%}
                {{ DIFF_TEXT.TAG(change, change_sub_section) }}
              {%- endfor -%}
            </td>
          {% elif key == change.DiffKey.version %}
            <td>Версия:</td>
            <td>
              {%- for key, change_sub_section in change_section.items() -%}
                {{ DIFF_TEXT.TAG(change, change_sub_section) }}
              {%- endfor -%}
            </td>
          {% elif key == change.DiffKey.files %}
            {% for key, change_sub_section in change_section.items() %}
              </tr><tr>
                <td>
                  Файл:
                </td>
                <td>
                  {{ DIFF_TEXT.TAG(change, change_sub_section) }}
                </td>
            {% endfor %}
          {% elif key == change.DiffKey.fields %}
            {% for key, change_sub_section in change_section.items() %}
              {% set field_kind = project_manager.field_kind(key) %}
              {% if field_kind -%}
                </tr><tr>
                  <td>
                    {{ field_kind.caption|e }}:
                  </td>
                  <td>
                    {{ DIFF_TEXT.TAG(change, change_sub_section) }}
                  </td>
              {% endif %}
            {% endfor %}
          {% elif key == change.DiffKey.comments %}
            {% for key, change_sub_section in change_section.items() %}
              </tr><tr>
                <td>
                  Комментарий:
                </td>
                <td>
                  {{ DIFF_TEXT.TAG(change, change_sub_section) }}
                </td>
            {% endfor %}
          {% endif %}
        </tr>
      {% endfor %}
    </tbody>
  </table>
{%- endmacro %}

